/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Clases;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 *
 * @author TVD
 */
public class VPrincipal extends javax.swing.JFrame {
    String pathArchivo="";
   String path = "imagenes\\";
   String nombreArchivo = "";
Gestor gestor;
    /**
     * Creates new form VPrincipal
     */
    public VPrincipal() {
        initComponents();
        comenzar();
       
    }
    public void comenzar()
    {
        gestor = new Gestor();
        cb_filtroResponsable.setModel(gestor.getResponsables());        
        cb_filtroCategoria.setModel(gestor.getCategorias());                                        
         txt_filtroVencimiento.setValue(gestor.getDefaultDate());         
         cb_abmResponsable.setModel(gestor.getResponsablesVisor());
        cb_abmCategoria.setModel(gestor.getCategoriasVisor());
        bt_visorEliminarTarea.setEnabled(false);
        bt_abmEliminarResponsable.setEnabled(false);
        bt_abmEliminarCategoria.setEnabled(false);
         int id = gestor.proximoResponsable();
        if(id == -1)txt_abmIdResponsable.setText(0+"");
        else{
            id+=1;
            txt_abmIdResponsable.setText(id+"");
        }
        int id2 = gestor.proximoCategoria();
        if(id2 == -1)txt_abmIdCategoria.setText(0+"");
        else{
            id2+=1;
            txt_abmIdCategoria.setText(id2+"");
        }
         cargarTablaInicio();
    
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        GrillaTareas = new javax.swing.JTable();
        PanelFiltros = new javax.swing.JPanel();
        PanelInternoFiltros = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txt_filtroVencimiento = new javax.swing.JFormattedTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txt_filtroTitulo = new javax.swing.JTextField();
        cb_filtroPrioridad = new javax.swing.JComboBox();
        cb_filtroResponsable = new javax.swing.JComboBox();
        cb_filtroCategoria = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        bt_Filtrar = new javax.swing.JButton();
        bt_reestablecerCampos = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        PanelVisorTareas = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        txt_visorTitulo = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txt_visorDescripcion = new javax.swing.JTextArea();
        jLabel12 = new javax.swing.JLabel();
        cb_visorPrioridad = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        txt_visorVencimiento = new javax.swing.JFormattedTextField();
        PanelPestañas = new javax.swing.JTabbedPane();
        PanelResponsable = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        jLabel19 = new javax.swing.JLabel();
        txt_abmEmailResponsable = new javax.swing.JTextField();
        txt_abmApodoResponsable = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        txt_abmNombreResponsable = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        bt_abmGuardarResponsable = new javax.swing.JButton();
        bt_abmEliminarResponsable = new javax.swing.JButton();
        txt_abmIdResponsable = new javax.swing.JTextField();
        bt_foto = new javax.swing.JButton();
        jLabel21 = new javax.swing.JLabel();
        cb_abmResponsable = new javax.swing.JComboBox();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        bt_abmNuevoResponsable = new javax.swing.JButton();
        PanelCategoria = new javax.swing.JPanel();
        jLabel25 = new javax.swing.JLabel();
        cb_abmCategoria = new javax.swing.JComboBox();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        bt_abmNuevaCategoria = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel29 = new javax.swing.JLabel();
        txt_abmNombreCategoria = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txt_abmDescripcionCategoria = new javax.swing.JTextArea();
        jLabel31 = new javax.swing.JLabel();
        bt_abmGuardarCategoria = new javax.swing.JButton();
        bt_abmEliminarCategoria = new javax.swing.JButton();
        txt_abmIdCategoria = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        txt_visorProgreso = new javax.swing.JFormattedTextField();
        jLabel15 = new javax.swing.JLabel();
        bt_visorEliminarTarea = new javax.swing.JButton();
        bt_visorGuardarTarea = new javax.swing.JButton();
        bt_visorNuevaTarea = new javax.swing.JButton();
        txt_visorId = new javax.swing.JTextField();
        jLabel32 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        GrillaTareas.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        GrillaTareas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Titulo", "Descripción", "Prioridad", "Vencimiento", "Responsable", "Categoria", "Progreso"
            }
        ));
        GrillaTareas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                GrillaTareasMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(GrillaTareas);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        PanelFiltros.setPreferredSize(new java.awt.Dimension(300, 440));
        PanelFiltros.setLayout(new java.awt.BorderLayout());

        PanelInternoFiltros.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        PanelInternoFiltros.setToolTipText("");
        PanelInternoFiltros.setPreferredSize(new java.awt.Dimension(300, 348));

        jLabel2.setText("Título:");

        jLabel3.setText("Prioridad:");

        jLabel4.setText("Responsable:");

        jLabel5.setText("Categoría:");
        jLabel5.setToolTipText("");

        txt_filtroVencimiento.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("d-MM-yyyy"))));
        txt_filtroVencimiento.setToolTipText("dd/mm/aaaa");

        jLabel6.setText("Vencimiento:");

        jLabel8.setText("Carga tareas que vencen hasta esta fecha");

        cb_filtroPrioridad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Todas", "Urgente", "Alta", "Media", "Baja" }));
        cb_filtroPrioridad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_filtroPrioridadActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jLabel7.setText("Formato: dd-mm-aaaa");

        bt_Filtrar.setText("Filtrar");
        bt_Filtrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_FiltrarActionPerformed(evt);
            }
        });

        bt_reestablecerCampos.setText("Reestablecer Campos");
        bt_reestablecerCampos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_reestablecerCamposActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout PanelInternoFiltrosLayout = new javax.swing.GroupLayout(PanelInternoFiltros);
        PanelInternoFiltros.setLayout(PanelInternoFiltrosLayout);
        PanelInternoFiltrosLayout.setHorizontalGroup(
            PanelInternoFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelInternoFiltrosLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel6)
                .addGap(14, 14, 14)
                .addComponent(txt_filtroVencimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addGap(449, 449, 449))
            .addGroup(PanelInternoFiltrosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelInternoFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(PanelInternoFiltrosLayout.createSequentialGroup()
                        .addComponent(bt_Filtrar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_reestablecerCampos))
                    .addGroup(PanelInternoFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel5)
                        .addGroup(PanelInternoFiltrosLayout.createSequentialGroup()
                            .addGroup(PanelInternoFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4)
                                .addComponent(jLabel3)
                                .addComponent(jLabel2))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(PanelInternoFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(txt_filtroTitulo)
                                .addComponent(cb_filtroPrioridad, 0, 200, Short.MAX_VALUE)
                                .addComponent(cb_filtroResponsable, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addComponent(jLabel8)
                        .addComponent(cb_filtroCategoria, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        PanelInternoFiltrosLayout.setVerticalGroup(
            PanelInternoFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelInternoFiltrosLayout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addGroup(PanelInternoFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txt_filtroTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(PanelInternoFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(cb_filtroPrioridad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(PanelInternoFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(cb_filtroResponsable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(PanelInternoFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(cb_filtroCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(PanelInternoFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txt_filtroVencimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel8)
                .addGap(18, 18, 18)
                .addGroup(PanelInternoFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_reestablecerCampos)
                    .addComponent(bt_Filtrar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        PanelFiltros.add(PanelInternoFiltros, java.awt.BorderLayout.LINE_END);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setText("FILTROS");
        PanelFiltros.add(jLabel1, java.awt.BorderLayout.PAGE_START);

        getContentPane().add(PanelFiltros, java.awt.BorderLayout.LINE_END);

        PanelVisorTareas.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        PanelVisorTareas.setPreferredSize(new java.awt.Dimension(1118, 250));

        jLabel9.setText("Titulo:");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel10.setText("VISOR DE TAREAS");

        jLabel11.setText("Descripción:");

        txt_visorDescripcion.setColumns(20);
        txt_visorDescripcion.setLineWrap(true);
        txt_visorDescripcion.setRows(5);
        jScrollPane3.setViewportView(txt_visorDescripcion);

        jLabel12.setText("Prioridad:");

        cb_visorPrioridad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Urgente", "Alta", "Media", "Baja" }));
        cb_visorPrioridad.setSelectedIndex(-1);

        jLabel13.setText("Vencimiento:");

        txt_visorVencimiento.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("d-MM-yyyy"))));

        PanelResponsable.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        PanelResponsable.setPreferredSize(new java.awt.Dimension(486, 160));
        PanelResponsable.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel9.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel9.setPreferredSize(new java.awt.Dimension(456, 159));

        jLabel19.setText("ID Responsable:");

        jLabel16.setText("NOMBRE:");

        jLabel18.setText("E-MAIL:");

        jLabel17.setText("APODO:");

        jLabel20.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel20.setText("RESPONSABLE ACTUAL:");

        bt_abmGuardarResponsable.setText("Guardar");
        bt_abmGuardarResponsable.setToolTipText("");
        bt_abmGuardarResponsable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_abmGuardarResponsableActionPerformed(evt);
            }
        });

        bt_abmEliminarResponsable.setText("Eliminar");
        bt_abmEliminarResponsable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_abmEliminarResponsableActionPerformed(evt);
            }
        });

        txt_abmIdResponsable.setEditable(false);

        bt_foto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Clases/sinfoto.jpg"))); // NOI18N
        bt_foto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_fotoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel20)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel9Layout.createSequentialGroup()
                                .addComponent(jLabel19)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txt_abmIdResponsable, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(bt_abmEliminarResponsable)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(bt_abmGuardarResponsable))
                            .addGroup(jPanel9Layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(jPanel9Layout.createSequentialGroup()
                                            .addComponent(jLabel17)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(txt_abmApodoResponsable, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel9Layout.createSequentialGroup()
                                            .addComponent(jLabel16)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(txt_abmNombreResponsable, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(jPanel9Layout.createSequentialGroup()
                                        .addGap(8, 8, 8)
                                        .addComponent(jLabel18)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(txt_abmEmailResponsable, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(6, 6, 6)))
                        .addGap(32, 32, 32)
                        .addComponent(bt_foto, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(24, 24, 24))))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addGap(7, 7, 7)
                .addComponent(jLabel20)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt_abmNombreResponsable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt_abmApodoResponsable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel17))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt_abmEmailResponsable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel18))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel19)
                                .addComponent(txt_abmIdResponsable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(bt_abmGuardarResponsable)
                                .addComponent(bt_abmEliminarResponsable))))
                    .addComponent(bt_foto, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(29, Short.MAX_VALUE))
        );

        PanelResponsable.add(jPanel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 50, -1, -1));

        jLabel21.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel21.setText("SELECCIONE UN RESPONSABLE");
        PanelResponsable.add(jLabel21, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 0, -1, -1));

        cb_abmResponsable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_abmResponsableActionPerformed(evt);
            }
        });
        cb_abmResponsable.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                cb_abmResponsableVetoableChange(evt);
            }
        });
        PanelResponsable.add(cb_abmResponsable, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, 150, -1));

        jLabel22.setText("Seleccione un Responsable ");
        PanelResponsable.add(jLabel22, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 10, -1, -1));

        jLabel23.setText("para modifiarlo o eliminarlo");
        PanelResponsable.add(jLabel23, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 30, -1, -1));

        jLabel24.setText("para asignar a una tarea ");
        PanelResponsable.add(jLabel24, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 20, -1, -1));

        bt_abmNuevoResponsable.setText("Nuevo Responsable");
        bt_abmNuevoResponsable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_abmNuevoResponsableActionPerformed(evt);
            }
        });
        PanelResponsable.add(bt_abmNuevoResponsable, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 10, -1, -1));

        PanelPestañas.addTab("Responsable", PanelResponsable);

        PanelCategoria.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel25.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel25.setText("SELECCIONE CATEGORIA");

        cb_abmCategoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_abmCategoriaActionPerformed(evt);
            }
        });

        jLabel26.setText("Seleccione una Categoría");

        jLabel27.setText("para asignar a una tarea ");

        jLabel28.setText("para modifiarla o eliminarla");

        bt_abmNuevaCategoria.setText("Nueva Categoría");
        bt_abmNuevaCategoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_abmNuevaCategoriaActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel29.setText("NOMBRE:");

        jLabel30.setText("DESCRIPCION:");

        txt_abmDescripcionCategoria.setColumns(20);
        txt_abmDescripcionCategoria.setRows(5);
        jScrollPane2.setViewportView(txt_abmDescripcionCategoria);

        jLabel31.setText("ID Categoría:");

        bt_abmGuardarCategoria.setText("Guardar");
        bt_abmGuardarCategoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_abmGuardarCategoriaActionPerformed(evt);
            }
        });

        bt_abmEliminarCategoria.setText("Eliminar");
        bt_abmEliminarCategoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_abmEliminarCategoriaActionPerformed(evt);
            }
        });

        txt_abmIdCategoria.setEditable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel29)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txt_abmNombreCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(bt_abmEliminarCategoria)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_abmGuardarCategoria))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel31)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txt_abmIdCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel30)
                        .addGap(0, 155, Short.MAX_VALUE))
                    .addComponent(jScrollPane2))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel29)
                    .addComponent(txt_abmNombreCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel30))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel31)
                            .addComponent(txt_abmIdCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(29, 29, 29)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(bt_abmGuardarCategoria)
                            .addComponent(bt_abmEliminarCategoria))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                        .addContainerGap())))
        );

        javax.swing.GroupLayout PanelCategoriaLayout = new javax.swing.GroupLayout(PanelCategoria);
        PanelCategoria.setLayout(PanelCategoriaLayout);
        PanelCategoriaLayout.setHorizontalGroup(
            PanelCategoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelCategoriaLayout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(PanelCategoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel25, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cb_abmCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PanelCategoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel28)
                    .addComponent(jLabel27)
                    .addComponent(jLabel26))
                .addGap(49, 49, 49)
                .addComponent(bt_abmNuevaCategoria)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelCategoriaLayout.createSequentialGroup()
                .addContainerGap(21, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        PanelCategoriaLayout.setVerticalGroup(
            PanelCategoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelCategoriaLayout.createSequentialGroup()
                .addGroup(PanelCategoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(PanelCategoriaLayout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(PanelCategoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(PanelCategoriaLayout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(jLabel28))
                            .addGroup(PanelCategoriaLayout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel27))
                            .addComponent(jLabel26)))
                    .addGroup(PanelCategoriaLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(bt_abmNuevaCategoria))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelCategoriaLayout.createSequentialGroup()
                        .addComponent(jLabel25)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(cb_abmCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(16, Short.MAX_VALUE))
        );

        PanelPestañas.addTab("Categoría", PanelCategoria);

        jLabel14.setText("Progreso:");

        txt_visorProgreso.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("##0"))));

        jLabel15.setText("ID TAREA:");

        bt_visorEliminarTarea.setText("Eliminar");

        bt_visorGuardarTarea.setText("Guardar");

        bt_visorNuevaTarea.setText("Nueva Tarea");

        txt_visorId.setEditable(false);

        jLabel32.setText("%");

        javax.swing.GroupLayout PanelVisorTareasLayout = new javax.swing.GroupLayout(PanelVisorTareas);
        PanelVisorTareas.setLayout(PanelVisorTareasLayout);
        PanelVisorTareasLayout.setHorizontalGroup(
            PanelVisorTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelVisorTareasLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelVisorTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(PanelVisorTareasLayout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txt_visorTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel10)
                    .addGroup(PanelVisorTareasLayout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane3)))
                .addGap(28, 28, 28)
                .addGroup(PanelVisorTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PanelVisorTareasLayout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addGap(18, 18, 18)
                        .addComponent(cb_visorPrioridad, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(PanelVisorTareasLayout.createSequentialGroup()
                        .addComponent(bt_visorEliminarTarea)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_visorGuardarTarea)
                        .addGap(18, 18, 18)
                        .addComponent(bt_visorNuevaTarea))
                    .addComponent(jLabel15)
                    .addGroup(PanelVisorTareasLayout.createSequentialGroup()
                        .addGroup(PanelVisorTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(PanelVisorTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txt_visorVencimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(PanelVisorTareasLayout.createSequentialGroup()
                                .addGroup(PanelVisorTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(txt_visorId, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                                    .addComponent(txt_visorProgreso, javax.swing.GroupLayout.Alignment.LEADING))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel32)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                .addComponent(PanelPestañas, javax.swing.GroupLayout.PREFERRED_SIZE, 491, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        PanelVisorTareasLayout.setVerticalGroup(
            PanelVisorTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelVisorTareasLayout.createSequentialGroup()
                .addGap(7, 7, 7)
                .addComponent(jLabel10)
                .addGap(18, 18, 18)
                .addGroup(PanelVisorTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txt_visorTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(cb_visorPrioridad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(PanelVisorTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PanelVisorTareasLayout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(PanelVisorTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(txt_visorVencimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(PanelVisorTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(txt_visorProgreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel32))
                        .addGap(11, 11, 11)
                        .addGroup(PanelVisorTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(txt_visorId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(PanelVisorTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(bt_visorEliminarTarea)
                            .addComponent(bt_visorGuardarTarea)
                            .addComponent(bt_visorNuevaTarea)))
                    .addGroup(PanelVisorTareasLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(PanelVisorTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addComponent(PanelPestañas)
        );

        getContentPane().add(PanelVisorTareas, java.awt.BorderLayout.PAGE_END);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cb_filtroPrioridadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_filtroPrioridadActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cb_filtroPrioridadActionPerformed

    private void bt_FiltrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_FiltrarActionPerformed
       cargarTabla();
    }//GEN-LAST:event_bt_FiltrarActionPerformed

    private void bt_reestablecerCamposActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_reestablecerCamposActionPerformed
        cargarTablaInicio();
    }//GEN-LAST:event_bt_reestablecerCamposActionPerformed

    private void GrillaTareasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_GrillaTareasMouseClicked
        Tarea t = ((ModeloTareas)GrillaTareas.getModel()).getItem(GrillaTareas.getSelectedRow());
        if (t != null) cargarVisor(t);
    }//GEN-LAST:event_GrillaTareasMouseClicked

    private void cb_abmResponsableVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {//GEN-FIRST:event_cb_abmResponsableVetoableChange
        System.out.println("hola");
    }//GEN-LAST:event_cb_abmResponsableVetoableChange

    private void cb_abmResponsableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_abmResponsableActionPerformed
       if(cb_abmResponsable.getSelectedIndex()==-1)return;
        Responsable r = (Responsable) cb_abmResponsable.getSelectedItem();
       cb_abmResponsable.updateUI();
       bt_abmEliminarResponsable.setEnabled(true);
       txt_abmNombreResponsable.setText(r.getNombre());
       txt_abmApodoResponsable.setText(r.getApodo());
       txt_abmEmailResponsable.setText(r.getEmail());
       txt_abmIdResponsable.setText(r.getId()+"");
       nombreArchivo = r.getPathFoto();
       pathArchivo = path + nombreArchivo;
       recargarBoton();
 
    }//GEN-LAST:event_cb_abmResponsableActionPerformed

    private void cb_abmCategoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_abmCategoriaActionPerformed
       if(cb_abmCategoria.getSelectedIndex()==-1)return;
        Categoria c = (Categoria) cb_abmCategoria.getSelectedItem();
        cb_abmCategoria.updateUI();        
        txt_abmNombreCategoria.setText(c.getNombre());
        txt_abmDescripcionCategoria.setText(c.getDescripcion());
        txt_abmIdCategoria.setText(c.getId()+"");
        bt_abmEliminarCategoria.setEnabled(true);
        
    }//GEN-LAST:event_cb_abmCategoriaActionPerformed

    private void bt_abmNuevoResponsableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_abmNuevoResponsableActionPerformed
        limpiarResponsables();
        int id = gestor.proximoResponsable();
        if(id == -1)txt_abmIdResponsable.setText(0+"");
        else{
            id+=1;
            txt_abmIdResponsable.setText(id+"");
        }
      
    }//GEN-LAST:event_bt_abmNuevoResponsableActionPerformed

    private void bt_abmGuardarResponsableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_abmGuardarResponsableActionPerformed
       int id = Integer.parseInt(txt_abmIdResponsable.getText());
        if(gestor.buscarResponsable(id))
       {
           //MODIFICA
           String res = verificarResponsable();
           if(res != "") 
           {
              JOptionPane.showMessageDialog(this,"No se pudo modificar: \n"+res,"Error", JOptionPane.ERROR_MESSAGE);
           }
           else
           {
               int nuevoId = gestor.modificarResponsable(id, txt_abmNombreResponsable.getText(),txt_abmApodoResponsable.getText(),txt_abmEmailResponsable.getText(), nombreArchivo);
               if(((Responsable)cb_abmResponsable.getSelectedItem()).getPathFoto() != nombreArchivo){
               try {
                   
                    BufferedImage i = ImageIO.read(new File(pathArchivo));
                   ImageIO.write(i, "png",new File(path+nombreArchivo));
               } catch (IOException ex) {
                   JOptionPane.showMessageDialog(this,"NO SE HA PODIDO GUARDAR LA FOTO QUIZAS YA EXISTA CON ESE NOMBRE SI ES LA MISMA FOTO ","Error", JOptionPane.ERROR_MESSAGE);
               }
               }
               if(nuevoId != id ) JOptionPane.showMessageDialog(this,"NO SE HA PODIDO GUARDAR EL RESPONSABLE ","Error", JOptionPane.ERROR_MESSAGE);
               else JOptionPane.showMessageDialog(this,"Se ha cargado el responsable correctamente ya puede utilizarla para cargar tareas ","Error", JOptionPane.ERROR_MESSAGE); 
           }       
       }
       else{
           //NUEVO
           String res = verificarResponsable();
            System.out.println("a:"+res);
           if(res != "") 
           {
              JOptionPane.showMessageDialog(this,"No se pudo registrar el responsable: \n"+res,"Error", JOptionPane.ERROR_MESSAGE);
           }
           else 
           {
               int nuevoId = gestor.crearNuevoResponsable(id, txt_abmNombreResponsable.getText(),txt_abmApodoResponsable.getText(),txt_abmEmailResponsable.getText(), nombreArchivo);
             
               try {
                    BufferedImage i = ImageIO.read(new File(pathArchivo));
                   ImageIO.write(i, "png",new File(path+nombreArchivo));
               } catch (IOException ex) {
                   JOptionPane.showMessageDialog(this,"NO SE HA PODIDO GUARDAR LA FOTO ","Error", JOptionPane.ERROR_MESSAGE);
               }
               if(nuevoId != id ) JOptionPane.showMessageDialog(this,"NO SE HA PODIDO GUARDAR EL RESPONSABLE ","Error", JOptionPane.ERROR_MESSAGE);
               else JOptionPane.showMessageDialog(this,"Se ha cargado el responsable correctamente ya puede utilizarla para cargar tareas ","Error", JOptionPane.ERROR_MESSAGE); 
           }
       
       
       }
    }//GEN-LAST:event_bt_abmGuardarResponsableActionPerformed

    private void bt_fotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_fotoActionPerformed
     
      JFileChooser elegir = new JFileChooser();
        FileNameExtensionFilter filtroImagen = new FileNameExtensionFilter("JPG, PNG & GIF","jpg","png","gif");
       elegir.setFileFilter(filtroImagen);
       int opcion = elegir.showOpenDialog(bt_foto);
        if (opcion == JFileChooser.APPROVE_OPTION) 
        {         
            try {
                pathArchivo = elegir.getSelectedFile().getCanonicalFile().getPath();
                nombreArchivo = elegir.getSelectedFile().getName();
                 recargarBoton();
                
//                BufferedImage i = ImageIO.read(elegir.getSelectedFile());
//              ImageIO.write(i, "png",new File("imagenes\\"+elegir.getSelectedFile().getName()));
            } catch (IOException ex) {
                System.out.println("Error: " + ex.getMessage());
                Logger.getLogger(VPrincipal.class.getName()).log(Level.SEVERE, null, ex);
            }                   
        }
        
    }//GEN-LAST:event_bt_fotoActionPerformed

    private void bt_abmNuevaCategoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_abmNuevaCategoriaActionPerformed
        limpiarCategorias();
        int id = gestor.proximoCategoria();
        if(id == -1)txt_abmIdCategoria.setText(0+"");
        else{
            id+=1;
            txt_abmIdCategoria.setText(id+"");
        }
        bt_abmEliminarCategoria.setEnabled(false);
    }//GEN-LAST:event_bt_abmNuevaCategoriaActionPerformed

    private void bt_abmGuardarCategoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_abmGuardarCategoriaActionPerformed
        int id = Integer.parseInt(txt_abmIdCategoria.getText());
        if(gestor.buscarCategoria(id))
       {
           //MODIFICA
           String res = verificarCategoria();
           if(res != "") 
           {
              JOptionPane.showMessageDialog(this,"No se pudo modificar: \n"+res,"Error", JOptionPane.ERROR_MESSAGE);
           }
           else
           {
               int nuevoId = gestor.modificarCategoria(id, txt_abmNombreCategoria.getText(),txt_abmDescripcionCategoria.getText());
               if(nuevoId != id ) JOptionPane.showMessageDialog(this,"NO SE HA PODIDO GUARDAR LA CATEGORIA ","Error", JOptionPane.ERROR_MESSAGE); 
               else JOptionPane.showMessageDialog(this,"Se ha cargado la categoria correctamente ya puede utilizarla para cargar tareas ","Error", JOptionPane.ERROR_MESSAGE);
           }       
       }
       else{
           //NUEVO
           String res = verificarCategoria();
            System.out.println("a:"+res);
           if(res != "") 
           {
              JOptionPane.showMessageDialog(this,"No se pudo registrar la categoría: \n"+res,"Error", JOptionPane.ERROR_MESSAGE);
           }
           else 
           {
               int nuevoId = gestor.crearNuevaCategoria(id, txt_abmNombreCategoria.getText(),txt_abmDescripcionCategoria.getText());
                if(nuevoId != id ) JOptionPane.showMessageDialog(this,"NO SE HA PODIDO GUARDAR LA CATEGORIA ","Error", JOptionPane.ERROR_MESSAGE); 
                else JOptionPane.showMessageDialog(this,"Se ha cargado la categoria correctamente ya puede utilizarla para cargar tareas ","Error", JOptionPane.ERROR_MESSAGE); 
               }
               
           }
        
    }//GEN-LAST:event_bt_abmGuardarCategoriaActionPerformed

    private void bt_abmEliminarResponsableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_abmEliminarResponsableActionPerformed
         int id = Integer.parseInt(txt_abmIdResponsable.getText());
        if(gestor.buscarResponsable(id)){
            Responsable r = (Responsable)cb_abmResponsable.getSelectedItem();
            if(!gestor.responsableTieneTareas(r))JOptionPane.showMessageDialog(this,"El responsable tiene tareas asignadas, no se puede eliminar","Error", JOptionPane.ERROR_MESSAGE); 
            else{
                int nuevoId = gestor.borrarResponsable(r);
                if (nuevoId != id)JOptionPane.showMessageDialog(this,"HA OCURRIDO UN ERROR EN LA ELIMINACION DEL RESPONSABLE","Error", JOptionPane.ERROR_MESSAGE); 
                else JOptionPane.showMessageDialog(this,"Se ha eliminado correctamente","Error", JOptionPane.ERROR_MESSAGE); 
            }
        }
        else
        {
          JOptionPane.showMessageDialog(this,"No se puede eliminar dado que no existe todavía ","Error", JOptionPane.ERROR_MESSAGE); 
        }
    }//GEN-LAST:event_bt_abmEliminarResponsableActionPerformed

    private void bt_abmEliminarCategoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_abmEliminarCategoriaActionPerformed
 int id = Integer.parseInt(txt_abmIdCategoria.getText());
        if(gestor.buscarCategoria(id)){
           Categoria c = (Categoria)cb_abmCategoria.getSelectedItem();
            if(!gestor.categoriaTieneTareas(c))JOptionPane.showMessageDialog(this,"La categoria tiene tareas asignadas, no se puede eliminar","Error", JOptionPane.ERROR_MESSAGE); 
            else{
                int nuevoId = gestor.borrarCategoria(c);
                if (nuevoId != id)JOptionPane.showMessageDialog(this,"HA OCURRIDO UN ERROR EN LA ELIMINACION DE LA CATEGORIA","Error", JOptionPane.ERROR_MESSAGE); 
                else JOptionPane.showMessageDialog(this,"Se ha eliminado correctamente","Error", JOptionPane.ERROR_MESSAGE); 
            }
        }
        else
        {
          JOptionPane.showMessageDialog(this,"No se puede eliminar dado que no existe todavía ","Error", JOptionPane.ERROR_MESSAGE); 
        }
    }//GEN-LAST:event_bt_abmEliminarCategoriaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
      
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VPrincipal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable GrillaTareas;
    private javax.swing.JPanel PanelCategoria;
    private javax.swing.JPanel PanelFiltros;
    private javax.swing.JPanel PanelInternoFiltros;
    private javax.swing.JTabbedPane PanelPestañas;
    private javax.swing.JPanel PanelResponsable;
    private javax.swing.JPanel PanelVisorTareas;
    private javax.swing.JButton bt_Filtrar;
    private javax.swing.JButton bt_abmEliminarCategoria;
    private javax.swing.JButton bt_abmEliminarResponsable;
    private javax.swing.JButton bt_abmGuardarCategoria;
    private javax.swing.JButton bt_abmGuardarResponsable;
    private javax.swing.JButton bt_abmNuevaCategoria;
    private javax.swing.JButton bt_abmNuevoResponsable;
    private javax.swing.JButton bt_foto;
    private javax.swing.JButton bt_reestablecerCampos;
    private javax.swing.JButton bt_visorEliminarTarea;
    private javax.swing.JButton bt_visorGuardarTarea;
    private javax.swing.JButton bt_visorNuevaTarea;
    private javax.swing.JComboBox cb_abmCategoria;
    private javax.swing.JComboBox cb_abmResponsable;
    private javax.swing.JComboBox cb_filtroCategoria;
    private javax.swing.JComboBox cb_filtroPrioridad;
    private javax.swing.JComboBox cb_filtroResponsable;
    private javax.swing.JComboBox cb_visorPrioridad;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextField txt_abmApodoResponsable;
    private javax.swing.JTextArea txt_abmDescripcionCategoria;
    private javax.swing.JTextField txt_abmEmailResponsable;
    private javax.swing.JTextField txt_abmIdCategoria;
    private javax.swing.JTextField txt_abmIdResponsable;
    private javax.swing.JTextField txt_abmNombreCategoria;
    private javax.swing.JTextField txt_abmNombreResponsable;
    private javax.swing.JTextField txt_filtroTitulo;
    private javax.swing.JFormattedTextField txt_filtroVencimiento;
    private javax.swing.JTextArea txt_visorDescripcion;
    private javax.swing.JTextField txt_visorId;
    private javax.swing.JFormattedTextField txt_visorProgreso;
    private javax.swing.JTextField txt_visorTitulo;
    private javax.swing.JFormattedTextField txt_visorVencimiento;
    // End of variables declaration//GEN-END:variables
    private void recargarBoton()
    {
         bt_foto.setIcon(new javax.swing.ImageIcon(pathArchivo));
    
    }
    private void cargarTablaInicio() {
            txt_filtroTitulo.setText("");
           cb_filtroResponsable.setSelectedIndex(0);
           cb_filtroResponsable.updateUI();
           cb_filtroCategoria.setSelectedIndex(0); 
           cb_filtroCategoria.updateUI();
           cb_filtroPrioridad.setSelectedIndex(0);
            txt_filtroVencimiento.setValue(gestor.getDefaultDate());
       cargarTabla();
    }
    private void cargarTabla()
    {
         String titulo = txt_filtroTitulo.getText();
        String sprioridad = cb_filtroPrioridad.getSelectedItem().toString();
        int prioridad=0;
        switch(sprioridad)
                {
                    case "Urgente": prioridad =  1;
                            break;
                    case "Alta": prioridad =  2;
                            break;
                    case "Media": prioridad =  3;
                            break;
                    case "Baja": prioridad =  4;
                            break;
                }
        int Responsable = ((Responsable)cb_filtroResponsable.getSelectedItem()).getId();
        int Categoria = ((Categoria)cb_filtroCategoria.getSelectedItem()).getId();
        Date fecha = (Date) txt_filtroVencimiento.getValue();
       GrillaTareas.setModel(gestor.cargarTabla(titulo, prioridad, Responsable, Categoria, fecha));
    
    }
    private void cargarVisor(Tarea t){
        bt_visorEliminarTarea.setEnabled(true);
        txt_visorTitulo.setText(t.getTitulo());
        txt_visorDescripcion.setText(t.getTexto());
        txt_visorProgreso.setValue(t.getCompletado());    
         txt_visorVencimiento.setValue(t.getVencimiento());
         cb_visorPrioridad.setSelectedIndex(t.getPrioridad()-1); 
         txt_visorId.setText(t.getId()+"");
        cb_abmResponsable.setSelectedIndex(t.getResponsable().getId()-1); 
        cb_abmCategoria.setSelectedIndex(t.getCategoria().getId()-1);


    }
    private void limpiarResponsables()
    {
        cb_abmResponsable.setSelectedIndex(-1);
        cb_abmResponsable.updateUI();
        txt_abmNombreResponsable.setText("");
        txt_abmApodoResponsable.setText("");
        txt_abmEmailResponsable.setText("");
        txt_abmIdResponsable.setText("");
        bt_foto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Clases/sinfoto.jpg")));
        pathArchivo = "sinfoto";
    
    }
   private String verificarResponsable()
   {    
       String res="";
       if(txt_abmNombreResponsable.getText().trim() == "")
       {
           res += "Debe ingresar un nombre \n";          
       }
       if(txt_abmApodoResponsable.getText().trim() == "")
       {
           res += "Debe ingresar un Apodo \n";
       }
       if(txt_abmEmailResponsable.getText().trim() == "")
       {
           res += "Debe ingresar un email \n";           
       }
       if("sinfoto" == pathArchivo)
       {
           nombreArchivo = "default.jpg";
           pathArchivo = path + nombreArchivo;
           recargarBoton();
       }
           return res;
   }
   private String verificarCategoria()
   {    
       String res="";
       if(txt_abmNombreCategoria.getText().trim() == "")
       {
           res += "Debe ingresar un nombre \n";          
       }
       if(txt_abmDescripcionCategoria.getText().trim() == "")
       {
           res += "Debe ingresar una Descripcion \n";
       }
        
           return res;
   }

    private void limpiarCategorias() {
         cb_abmCategoria.setSelectedIndex(-1);
        cb_abmCategoria.updateUI();
        txt_abmNombreCategoria.setText("");
        txt_abmDescripcionCategoria.setText("");
        txt_abmIdCategoria.setText("");  
        
        
    }
       
}
